import { defineConfig, resolveBaseUrl } from 'vite'
import vue from '@vitejs/plugin-vue'
import postCssPxToRem from "postcss-pxtorem"
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';
import { resolve } from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(),
  Components({
    resolvers: [VantResolver()],
  }),
  ],
  resolve: {
    // ↓路径别名，主要是这部分
    alias: {
      "@": resolve(__dirname, "./src")
    }
  },
  //配置src的路径别名 @ 
  css: {
    postcss: {
      plugins: [
        postCssPxToRem({
          rootValue: 37.5, // 1rem的大小
          propList: ['*'], // 需要转换的属性，这里选择全部都进行转换
        })
      ]
    }
  },
  server: {
    open: true,
    port: 8888,
    proxy: {
      // 选项写法
      "/api": {
        target: "http://gmall-h5-api.atguigu.cn",
        changeOrigin: true, //重写api的  看路径有没有
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
      "/item": {
        target: "https://m.you.163.com",
        changeOrigin: true,
      },
      "/xhr": {
        target: "https://m.you.163.com",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/xhr/, ""),
      },
      "/api-dev": {
        target: "https://m.you.163.com",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api-dev/, '')
      },
    },
  },
})

